package com.zy.mc_module.ui.micang;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.market.sdk.utils.CollectionUtils;
import com.zy.mc_module.base.kotlin.BaseActivity;
import com.zy.mc_module.databinding.ActivityStarPersonBinding;
import com.zy.mc_module.mvp.bean.MasterLevelBean;
import com.zy.mc_module.ui.micang.adapter.StarConfigAdapter;
import com.zy.mc_module.utils.retrofit.error.ThdException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 星级达人
 */
public class StarPersonActivity extends BaseActivity<RiceContract.View, RicePresenter, ActivityStarPersonBinding> implements RiceContract.View {
    private StarConfigAdapter adapter;
    @NonNull
    @Override
    public ActivityStarPersonBinding getViewBinding() {
        return ActivityStarPersonBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initView() {
        super.initView();
        binding.customhead.setLeftClickListener(view -> finish());
        adapter = new StarConfigAdapter(new ArrayList<>());
        binding.rcvStarConfig.setLayoutManager(new LinearLayoutManager(context));
        binding.rcvStarConfig.setAdapter(adapter);
        getPresenter().masterList(context);
    }

    @Override
    public void onError(ThdException error) {

    }

    @Override
    public <T> void onSuccess(T t, int type) {
        if (type == RicePresenter.MASTER_LIST)
        {
            List<MasterLevelBean> levelBeanList = (List<MasterLevelBean>) t;
            if (CollectionUtils.isEmpty(levelBeanList))
            {
                showEmpty();
            }else {
                adapter.setData(levelBeanList);
            }
        }
    }

    @Override
    public void onError(ThdException error, int type) {

        showEmpty();
    }
}
